package com.solo.servlet;

import com.solo.entity.User;
import com.solo.service.UserService;
import com.solo.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "UserServlet", value = "/index")
public class UserServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;

	UserService userService = new UserServiceImpl();

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		response.setContentType("text/html;charset=utf-8");
		List<User> userList = userService.selectAllUser();
		request.setAttribute("userList", userList);
		request.getRequestDispatcher("/user_list.jsp").forward(request,
				response);
	}
}
